#
#	MediaCenter Makefile
#

#
# Change this to your GCC version.
#
CC = g++

#
# Universal cflags
#
CFLAGS = -Wall -pipe -fPIC -funroll-loops -DHAVE_PCAP

ifeq ($(debug),1)
        OBJ_PREFIX = debug
        CFLAGS += -g -pg -DWITH_WIIUSE_DEBUG -D_LINUX
else
        OBJ_PREFIX = release
        CFLAGS += -O2 -D_LINUX
endif

OBJ_DIR = $(OBJ_PREFIX)-$(shell $(CC) -v 2>&1|grep ^Target:|cut -d' ' -f2)

#
# Linking flags
#
LDFLAGS = -L./wiiuse/$(OBJ_DIR) \
	-L. clsockets/objdebug/SimpleSocket.o clsockets/objdebug/ActiveSocket.o \
	-lm -lwiiuse \
	-lboost_thread -lboost_system 
#
# Target binaries (always created as BIN)
#
BIN = ./$(OBJ_DIR)/MediaCenter

#
# Inclusion paths.
#
INCLUDES = -I./wiiuse/ -I./clsockets/
#INCLUDES = -I../../boost-trunk/

#
# Generate a list of object files
#
OBJS = $(OBJ_DIR)/MediaCenter.o $(OBJ_DIR)/Wiimote.o $(OBJ_DIR)/WiimoteManager.o $(OBJ_DIR)/TiVoConnection.o

###############################
#
# Build targets.
#
###############################

all: $(BIN)

clean:
	@$(MAKE) -C wiiuse $@
	@-rm $(OBJS) 2> /dev/null

distclean:
	@$(MAKE) -C wiiuse $@
	@-rm -r debug-* release-* 2> /dev/null

install:
	@$(MAKE) -C wiiuse $@
	@if [ -e $(BIN) ]; then \
		cp -v $(BIN) /usr/bin ; \
	fi


$(BIN): mkdir $(OBJS)
	$(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $(BIN)

$(OBJ_DIR)/%.o: %.cpp
	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

mkdir:
	@if [ ! -d $(OBJ_DIR) ]; then \
		mkdir $(OBJ_DIR); \
	fi

run: all
	LD_LIBRARY_PATH=`pwd`/wiiuse/$(OBJ_DIR):$(LD_LIBRARY_PATH) $(BIN)

